home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OCFSRC.PAK / AUTOSTCK.CPP < prev    next >
C/C++ Source or Header  |  1997-05-06  |  3KB  |  85 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectComponents
  3. // Copyright (c) 1994, 1997 by Borland International, All Rights Reserved
  4. //
  5. // $Revision:   2.3  $
  6. //
  7. // OLE Automation - Implementation of TAutoStack
  8. //----------------------------------------------------------------------------
  9. #include <ocf/pch.h>
  10. #if !defined(OCF_APPDESC_H)
  11. # include <ocf/appdesc.h>
  12. #endif
  13. #if !defined(OCF_OCREG_H)
  14. # include <ocf/ocreg.h>
  15. #endif
  16. #if !defined(OCF_OCCTRL_H) && defined(BI_PLAT_WIN32)
  17. # include <ocf/occtrl.h>
  18. #endif
  19.  
  20. //----------------------------------------------------------------------------
  21. // TAutoStack implementation
  22. //
  23.  
  24. TAutoStack::TAutoStack(DISPID id, VARIANT *stack, TLocaleId locale,
  25.                        int argcount, int named, long far* map,
  26.                        TServedObject* owner)
  27. :
  28.   Owner(owner),
  29.   Stack((TAutoVal*)stack),
  30.   LangId(LANGIDFROMLCID(locale)),
  31.   ArgCount(argcount),
  32.   NamedCount(named),
  33.   NamedIds(map),
  34.   CurrentArg(-1),
  35.   DispId(id)
  36. {
  37. }
  38.  
  39. TAutoStack::~TAutoStack()
  40. {
  41.   TAutoVal* val;
  42.   for (val = Stack; ArgCount; --*const_cast<int*>(&ArgCount), val++)
  43.     val->Restore();
  44. }
  45.  
  46. TAutoVal& TAutoStack::operator [](int index)
  47. {
  48.   TAutoSymbol* argSymbol = NULL;
  49.   if (index < ArgSymbolCount)
  50.     argSymbol = index >= 0 ? Symbol + index + 1 : Symbol;
  51.   int vIndex = ArgCount - index - 1;        // index if not a named argument
  52.   if (index == TAutoStack::SetValue ||      // property value to set
  53.       index >= ArgCount-NamedCount) {       // named or out of range
  54.     for (vIndex = NamedCount; --vIndex >= 0; )
  55.       if (NamedIds[vIndex] == index) {
  56.         break;
  57.       }
  58.   }
  59.   TAutoVal* val;
  60.   if (vIndex >= 0) {
  61.     CurrentArg = vIndex;   // save index for error return
  62.     val = Stack[vIndex].DereferenceVariant();
  63.     val->SetLocale(LangId);
  64.     if ((val->GetDataType() == atString) &&
  65.         ((argSymbol) && (argSymbol->IsEnum()) &&
  66.          (argSymbol->GetEnum()->Convert(*val, Default))))
  67.       return Default;
  68.   }
  69.   else if (index == TAutoStack::SetValue) {
  70.     TXAuto::Raise(TXAuto::xParameterMissing);
  71.   }
  72.   else {
  73.     val = &Default;
  74.     val->SetLocale(LangId);
  75.     if (!argSymbol)
  76.       TXAuto::Raise(TXAuto::xNoArgSymbol);
  77.     const char* dfltStr = argSymbol->Doc.Translate(LangId); // load default
  78.     if (!dfltStr)
  79.       TXAuto::Raise(TXAuto::xNoDefaultValue);
  80.     Default = dfltStr;    // makes a BSTR in order to use OLE conversions
  81.   }
  82.   return *val;
  83. }
  84.  
  85.